package com.woniuxy.smrbac.service.impl;

import com.woniuxy.smrbac.bean.Role;
import com.woniuxy.smrbac.mapper.RoleMapper;
import com.woniuxy.smrbac.service.IRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author linke
 * @version 1.0
 * @className: RoleServiceImpl
 * @description: 角色操作服务实现类
 * @date 2021/11/13 1:40
 * 将实现类交给Spring容器管理
 * @Transactional 只读事务声明，用于对查询事务的优化
 */
@Transactional(readOnly = true)
@Service
public class RoleServiceImpl implements IRoleService {
    /**
     * 注入持久层对象
     */
    @Resource
    private RoleMapper roleMapper;

    @Override
    public List<Role> findAll() {

        return roleMapper.findByAll();
    }
    //REPEATABLE_READ可重复读取级别    在执行修改操作提交后，只允许查询
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void saveRole(Role role) {
        roleMapper.saveRole(role);
    }

    //REPEATABLE_READ可重复读取级别    在执行修改操作提交后，只允许查询
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void updateRole(Role role) {
        roleMapper.updateRole(role);
    }

    @Override
    public Role getOneByID(Integer id) {
        return roleMapper.getOneByID(id);
    }

    //REPEATABLE_READ可重复读取级别    在执行修改操作提交后，只允许查询
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void deleteRole(Integer id) {
        roleMapper.deleteRole(id);
    }
}
